package manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import manage.dao.RecordMapper;
import manage.model.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecordServiceImpl {
    @Autowired
    private RecordMapper recordMapper;

    public PageInfo<Record> selectAll(String page, String limit) {
        int pu = Integer.parseInt(page);
        int li = Integer.parseInt(limit);

        PageHelper.startPage(pu,li);
        List<Record> list = recordMapper.selectAll();
        PageInfo<Record> pageInfo = new PageInfo<Record>(list);
        return pageInfo;
    }

    public String insert(Record record) {

        int i = recordMapper.insert(record);
        if(i>0)
            return "success";
        return "fail";
    }

    public String del(Integer id) {
        int i = recordMapper.deleteByPrimaryKey(id);
        if(i>0)
            return "success";
        return "fail";
    }

    public Record select(Integer id) {
        return recordMapper.selectByPrimaryKey(id);
    }
    public String update(Record record){
        if(recordMapper.updateByPrimaryKey(record)>0)
            return "success";
        return "fail";
    }
}
